import React, { Component } from 'react';
import { Form, Input, message, Button } from 'antd'
import { apiUpdateOrderNotifyUrl, apiGetOrderNotifyUrl, apiUpdateStoreVirtualConfig, apiGetStoreVirtualConfig } from '@/api/afterSaleAddress/basicConfig'
export default class BasicConfig extends Component {
    constructor() {
        super()
        this.configFormRef = React.createRef()
        this.state = {}
    }
    componentDidMount() {
        this.getData()
    }
    getData = () => {
        apiGetStoreVirtualConfig().then(res => {
            if (res.code == 0) {
                this.configFormRef.current.setFieldsValue({
                    orderNotifyUrl: res.data.orderNotifyUrl,
                    // defaultMemberId: res.data.defaultMemberId
                })
            }
        })
    }
    onFinish = (e) => {
        this.configFormRef.current.validateFields().then(values => {
            apiUpdateStoreVirtualConfig({ ...values }).then(res => {
                if (res.code == 0) {
                    message.success('保存成功')
                } else {
                    message.error('保存失败')
                }
            })
        }).catch(err => {
            console.warn(err);
        })
    }
    render() {
        return (
            <div>
                <Form
                    name="basic"
                    ref={this.configFormRef}
                    onFinish={this.onFinish}
                    autoComplete="off"
                >
                    <Form.Item
                        label="订单回调地址"
                        name="orderNotifyUrl"
                        style={{ width: 400 }}

                        rules={[
                            {
                                required: false,
                                message: '请输入订单回调地址',
                            },
                        ]}
                    >
                        <Input onBlur={this.onInputBlur} />
                    </Form.Item>
                    {/* <Form.Item
                        label="用户ID"
                        name="defaultMemberId"
                        style={{ width: 400 }}
                        rules={[
                            {
                                required: false,
                                message: '请输入用户ID',
                            },
                        ]}
                    >
                        <Input onBlur={this.onInputBlur} />
                    </Form.Item> */}
                    <Form.Item
                        wrapperCol={{
                            offset: 8,
                            span: 16,
                        }}
                    >
                        <Button type="primary" htmlType="submit">
                            保存
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        );
    }
}
